{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-input-inline layui-form">
                            <select name="role" id="role" lay-search="">
                                <option  value="">不限状态</option>
                                <option  value="1">未绑定</option>
                                <option  value="2">已绑定</option>
                            </select>
                        </div>
                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="用户名/地区"/>
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <label class="layui-form-label">合伙人显示：</label>
                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" name="number" lay-verify="required|percent" class="layui-input" placeholder="合伙人显示数量" value="{$admin.partner}"/>
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search1">提交</button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12" {neq name=":session('uid')" value="1"}style="display:none;"{/neq}>
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.href('{:url('createAccount')}');">
                            生成账号
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.user_image}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />
                    </script>
                    <!--角色模板-->
                    <script type="text/html" id="titleTpl">
                        {{# if(d.par_status == 1){ }}
                            未绑定
                        {{# }else{ }}
                            已绑定
                        {{# } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.href('{:url('partnerAdd1')}?id={{d.par_id}}')" class="btn btn-primary btn-xs m-r-xs" >编辑</a>
                        {{# if(d.par_status == 1){ }}
                        <a href="javascript:;" onclick="wk.href('{:url('partnerAdd')}?id={{d.par_id}}')" class="btn btn-primary btn-xs m-r-xs" >绑定</a>
                        {{# if(d.par_user_id == null || d.par_user_id == ''){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.par_id}}','{:url('partnerDel')}')" class="btn btn-danger btn-xs m-r-xs" >删除</a>
                        {{# } }}
                        {{# } }}
                        {{# if(d.par_status == 2){ }}
                        <a href="javascript:;" onclick="wk.href('{:url('money')}?id={{d.user_id}}')" class="btn btn-primary btn-xs m-r-xs" >查看收益</a>
                        <a href="javascript:;" onclick="wk.href('{:url('partneredit')}?id={{d.par_id}}')" class="btn btn-primary btn-xs m-r-xs" >解绑</a>
                        {{# } }}
                        <a href="javascript:;" onclick="son({{d.par_id}})" class="btn btn-primary btn-xs m-r-xs" >排序</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("partner/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'numbers', width: 80, title: '序号'}
                , {field: 'user_username', width: '', title: '用户名', align: 'center'}
                , {field: 'user_phone', width: '', title: '手机号', align: 'center'}
                , {field: 'username', width: '', title: '代理名称', align: 'center'}
                , {field: 'district', width: '', title: '代理区域', align: 'center'}
                , {field: 'par_status', width: '', title: '状态', align: 'center',templet: '#titleTpl'}
                , {field: 'par_add_time', width: '', title: '绑定时间', align: 'center'}
                , {width: '', title: '收益比例', align: 'center',templet:"<div>{{d.par_percent || 0 }}%</div>"}
                , {fixed: 'right', field:'par_sort', width: 80, title: '排序值', align: 'center'}
                , {fixed: 'right', width: 300, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
        });

        form.verify({
            percent: [
                /^[1-9]\d*$/
                ,'非零正整数'
            ]
        });

        form.on('submit(LAY-search1)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('partnerNum')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });

    });
    function son(shop_id) {
        layer.prompt({
            formType: 2,
            title: '修改排序值',
            area: ['200px', '50px'],
            btn: ['确认', '取消'],
            maxlength:11,
        },function(value, index, elem){
            var pattern = /^[1-9]\d*$/;
            if(!pattern.test(value)){
                wk.error('请填写正确的排序值');
                return;
            }
            send1(shop_id,value);
            layer.close(index);
        });
    }
    function send1(shop_id,value){
        $.ajax({
            url: "{:url('addSort')}",
            type: "post",
            dataType: "json",
            data: {id:shop_id,num:value},
            success: function (res) {
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    });
                } else if (res.code == 100){
                    layer.msg(res.msg,{icon:2,time:1500,shade: 0.1});
                }
            }
        });
    }
</script>
</body>
</html>